/*
 * =====================================================================================
 *
 *       Filename:  main.cc
 *
 *    Description:
 *
 *        Version:  1.0
 *        Created:  2022年01月21日 11时24分06秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  first_name last_name (fl), fl@my-company.com
 *        Company:  my-company
 *
 * =====================================================================================
 */

#include <iostream>
#include <thread>
#include <atomic>

using namespace std;

atomic_long total {
    0};                //原子数据类型

void func(int) {
    long long i;

    for (i = 0; i < 100000000LL; i++) {
        total += i;
        cout << "total: " << total << endl;
    }
}

int main() {
    thread t1(func, 0);
    thread t2(func, 0);
    t1.join();
    t2.join();
    cout << "total: " << total << endl;
}
